﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gollie.DataTables;
using NLog;

namespace Gollie.Controls
{
    public partial class BaseUserControl : System.Web.UI.UserControl
    {
		protected static Logger logger = LogManager.GetCurrentClassLogger();

        public BaseUserControl()
        {
            this.Load += new EventHandler(BaseUserControl_Load);
        }

        void BaseUserControl_Load(object sender, EventArgs e)
        {
            this.PreLoadHandler(sender, e);

            if (this.IsPostBack)
                this.OnPostBack(sender, e);
            else
            {
                this.WriteLog();
                this.OnFirstHit(sender, e);
            }

            this.PostLoadHandler(sender, e);
        }

        protected UserInfo UserInfo
        {
            get { return (UserInfo)Session["userinfo"]; }
        }

		protected bool IsLoggedIn
		{
			get { return this.UserInfo != null; }
		}

		protected bool IsSecret
		{
			get { return IsLoggedIn && this.UserInfo.IsSecret; }
		}

		protected OrderBasketData OrderBasketData
		{
			get
			{
				OrderBasketData obd = Session["orderbasket"] as OrderBasketData;
				if (obd == null)
				{
					obd = new OrderBasketData();
					OrderBasketData = obd;
				}

				return obd;
			}
			set { Session["orderbasket"] = value; }
		}

        protected virtual void PreLoadHandler(object sender, EventArgs e)
        { }

        protected virtual void PostLoadHandler(object sender, EventArgs e)
        { }

        protected virtual void OnPostBack(object sender, EventArgs e)
        { }

        protected virtual void OnFirstHit(object sender, EventArgs e)
        { }

        protected virtual void WriteLog()
        {

		}
    }
}